using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WikiApp.Pages
{
    public interface ICategoryPage
    {
        void AddItem(string title, string description, string yamlFileName);
    }

    public class CategoryItem
    {
        public string Title { get; }
        public string Description { get; }
        public string YamlFileName { get; }

        public CategoryItem(string title, string description, string yamlFileName)
        {
            Title = title;
            Description = description;
            YamlFileName = yamlFileName;
        }
    }

    public partial class CategoryPage : Page, ICategoryPage
    {
        public string PageTitle { get; }
        public ObservableCollection<CategoryItem> CategoryItems { get; }
        private readonly string _pageType;

        public CategoryPage(string title, string pageType)
        {
            InitializeComponent();
            PageTitle = title;
            _pageType = pageType;
            CategoryItems = new ObservableCollection<CategoryItem>();
            DataContext = this;
        }

        void ICategoryPage.AddItem(string title, string description, string yamlFileName)
        {
            CategoryItems.Add(new CategoryItem(title, description, yamlFileName));
        }

        private void CategoryItem_Click(object sender, MouseButtonEventArgs e)
        {
            if (sender is FrameworkElement element && element.DataContext is CategoryItem item)
            {
                if (NavigationService != null)
                {
                    NavigationService.Navigate(BaseContentPage.CreatePage(item.Title, item.YamlFileName, _pageType));
                }
            }
        }
    }
} 